
from flask import Flask, session, Response, request
import os

app = Flask(__name__, template_folder='template', static_url_path='/', static_folder='resource')
app.config['SECRET_KEY'] = os.urandom(24)


@app.route("/")
def index():
    return "Welcome to develop woniu blog"

@app.route('/sess')
def sess():
    session['username']="woniuxy"
    session['nickname'] = "强哥"
    session['role']='editor'
    return 'Done'
@app.route("/sc/read")
def scread():
    return '你当前的昵称为：%s'% session.get('username')

@app.route('/set_cookie')
def set_cookie():
    response = Response('设置cooke')
    response.set_cookie('name', '朱宇')
    return response

@app.route('/get_cookie')
def get_cookie():
    return request.cookies.get('name')

@app.route('/test')
def test():
    username = request.args.get('username')
    password = request.args.get('password')
    return '你的用户名为：%s，密码为：%s' % (username, password)


@app.route('/article/<int:articleid>-<page>')
def article(articleid, page):
    return f"你正在访问编号为： {articleid} 的文章，目前是第 {page} 页."

@app.route('/user/login', methods=['POST'])
def login():
    username = request.form.get('username')
    password = request.form.get('password')
    if username == 'woniuxy" and password == "123456':
        return'登录成功'
    else:
        return'登录失败'


if __name__ == '__main__':
   app.run(port=80,debug=True)


